
#include<experimental/filesystem>
//#include<jsoncpp/json/json.h>
#include"myconfig.hpp"
#include"data.hpp"
#include"util.hpp"
#include"hot.hpp"
#include"server.hpp"
#include<pthread.h>
void FileUtilTest(const std::string &filename)
{
 //*********************************************** */
//测试1
// cloud::FileUtil fu(filename);  
 //std::cout<<fu.FileName()<<std::endl;
 //std::cout<<fu.FileSize()<<std::endl;
 //std::cout<<fu.LastATime()<<std::endl;
 //std::cout<<fu.LastMTime()<<std::endl;
 //*********************************************** */
//测试2
 // cloud::FileUtil fu(filename);  
//  std::string body;
 // fu.GetContent(&body);
 //   cloud::FileUtil st("./52.txt"); 
 //  st.SetContent(body);
  //*********************************************** */
  // std::string packname=filename+".lz";
  // cloud::FileUtil fu(filename);
  // fu.Compress(packname);
  // cloud::FileUtil pfu(packname);
   //pfu.UnCompress("./hello.txt");
   //return ;
    //*********************************************** */
    //cloud::FileUtil fu(filename);
    //fu.CreateDirectory();
    //std::vector<std::string>arry;
    ///fu.ScanDirectory(&arry);
    //for(auto &a:arry)
    //{
    //  std::cout<<a<<std::endl;
    //}
    //return ;
     //*********************************************** */

}
void JsonUtilTest()   //序列化反序列化测试函数
{

const char *name="小张";
int age=19;
float score[]={95,68,74};
Json::Value root;
root["姓名"]=name;
root["年龄"]=22;
root["成绩"].append(score[0]);
root["成绩"].append(score[1]);
root["成绩"].append(score[2]);
std::string json_str;
cloud::JsonUtil::Serialize(root,&json_str);
std::cout<<json_str<<std::endl;

Json::Value val;
cloud::JsonUtil::UnSerialize(json_str,&val);
std::cout<<val["姓名"].asString()<<std::endl;
std::cout<<val["年龄"].asInt()<<std::endl;
for(int i=0;i<val["成绩"].size();i++)
{
   std::cout<<val["成绩"][i].asFloat()<<std::endl;


}

}
void ConfigTest()
{
cloud::Config *config=cloud::Config::GetInstance();
std::cout<<config->GetHotTime()<<std::endl;
std::cout<<config->GetServerPort()<<std::endl;
std::cout<<config->GetServerIp()<<std::endl;
std::cout<<config->GetDownloadPrefix()<<std::endl;
std::cout<<config->GetpackFileSuffix()<<std::endl;
std::cout<<config->GetPackDir()<<std::endl;
std::cout<<config->GetBackDir()<<std::endl;
std::cout<<config->GetBackupFile()<<std::endl;

}
/*void datatest(const std::string &filename)
{
  /* cloud::BackupInfo info;
   info.NewBackupInfo(filename);
   std::cout<<"是否被压缩"<<info.pack_flag<<std::endl;
   std::cout<<"文件大小"<<info.fsize<<std::endl;
   std::cout<<"文件最后修改时间"<<info.mtime<<std::endl;
   std::cout<<"文件最后访问时间"<<info.atime<<std::endl;
   std::cout<<"文件的真实路径"<<info.real_path<<std::endl;
   std::cout<<"文件的压缩包路径"<<info.pack_path<<std::endl;
   std::cout<<"文件的下载路径"<<info.url<<std::endl;*/

  // cloud::BackupInfo info;
   //info.NewBackupInfo(filename);
  // cloud::DataManger data;
   //data.Insert(info);

  /* std::cout<<"-------------------------insert and getonebyurl----------------"<<std::endl;
   cloud::BackupInfo tmp;
  
  
   data.GetOneByURL("/download/bundle.h",&tmp);
   std::cout<<"是否被压缩"<< tmp.pack_flag<<std::endl;
   std::cout<<"文件大小"<< tmp.fsize<<std::endl;
   std::cout<<"文件最后修改时间"<< tmp.mtime<<std::endl;
   std::cout<<"文件最后访问时间"<< tmp.atime<<std::endl;
   std::cout<<"文件的真实路径"<< tmp.real_path<<std::endl;
   std::cout<<"文件的压缩包路径"<< tmp.pack_path<<std::endl;
   std::cout<<"文件的下载路径"<< tmp.url<<std::endl;

    std::cout<<"-------------------------modify and update----------------"<<std::endl;
   info.pack_flag=true;
   data.Update(info);
   std::vector<cloud::BackupInfo>arry;
   data.GetAll(&arry);
   for(auto &a:arry)
   {
     std::cout<<"是否被压缩"<< a.pack_flag<<std::endl;
     std::cout<<"文件大小"<< a.fsize<<std::endl;
     std::cout<<"文件最后修改时间"<<a.mtime<<std::endl;
     std::cout<<"文件最后访问时间"<< a.atime<<std::endl;
     std::cout<<"文件的真实路径"<< a.real_path<<std::endl;
     std::cout<<"文件的压缩包路径"<< a.pack_path<<std::endl;
     std::cout<<"文件的下载路径"<< a.url<<std::endl;


   }
  /* std::cout<<"-------------------------realpath----------------"<<std::endl;
   data.GetOneByRealPath(filename,&tmp);
   std::cout<<"是否被压缩"<< tmp.pack_flag<<std::endl;
   std::cout<<"文件大小"<< tmp.fsize<<std::endl;
   std::cout<<"文件最后修改时间"<< tmp.mtime<<std::endl;
   std::cout<<"文件最后访问时间"<< tmp.atime<<std::endl;
   std::cout<<"文件的真实路径"<< tmp.real_path<<std::endl;
   std::cout<<"文件的压缩包路径"<< tmp.pack_path<<std::endl;
   std::cout<<"文件的下载路径"<< tmp.url<<std::endl;*/

 /*  cloud::DataManger data;
    std::vector<cloud::BackupInfo>arry;
   data.GetAll(&arry);
   for(auto &a:arry)
   {
     std::cout<<"是否被压缩"<< a.pack_flag<<std::endl;
     std::cout<<"文件大小"<< a.fsize<<std::endl;
     std::cout<<"文件最后修改时间"<<a.mtime<<std::endl;
     std::cout<<"文件最后访问时间"<< a.atime<<std::endl;
     std::cout<<"文件的真实路径"<< a.real_path<<std::endl;
     std::cout<<"文件的压缩包路径"<< a.pack_path<<std::endl;
     std::cout<<"文件的下载路径"<< a.url<<std::endl;


   }




}*/
cloud::DataManger *_data;
void HotTest(){
  // _data=new cloud::DataManger();
   cloud::HotManger hot;
   hot.RunModule();

}
void servertest()
{
  
  cloud::Service srv;

  srv.RunModule();
  


}

int main(int argc,char*argv[])
{   
  _data=new cloud::DataManger();
   //FileUtilTest(argv[1]);//   ./cloud  cloud.cpp   文件名保存在argv[1]中
   //return 0;
   // JsonUtilTest();
   // ConfigTest();
   //datatest(argv[1]);
   //HotTest();
   //servertest();
   std::thread thread_hot_manager(HotTest);
   std::thread thread_service(servertest);
   thread_hot_manager.join();
   thread_service.join();

}


